package com.geccocrawler.gecco.request;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;

import java.util.Map;

public class HttpPostRequest extends AbstractHttpRequest {

    private static final long serialVersionUID = -4451221207994730839L;

    private Map<String, String> fields;

    public HttpPostRequest() {
        super();
        fields = Maps.newHashMap();
    }

    public HttpPostRequest(String url) {
        super(url);
        fields = Maps.newHashMap();
    }

    public Map<String, String> getFields() {
        return fields;
    }

    public void setFields(Map<String, String> fields) {
        this.fields = fields;
    }

    public void addField(String name, String field) {
        fields.put(name, field);
    }

    public String getField(String name) {
        return fields.get(name);
    }

    public static HttpPostRequest fromJson(JSONObject request) {
        return JSON.toJavaObject(request, HttpPostRequest.class);
    }
}
